﻿@{
    ViewBag.Title = "SerRolePer";
}
@using FMS.Model;
@model FMS.UI.Areas.Admin.ViewModel.SetRolePer
@section headsecion{
    <style type="text/css">
        .btn1 {
            font-size: 9pt;
            color: #003399;
            border: 1px #003399 solid;
            color: #006699;
            border-bottom: #93bee2 1px solid;
            border-left: #93bee2 1px solid;
            border-right: #93bee2 1px solid;
            border-top: #93bee2 1px solid;
            background-color: #e8f4ff;
            font-style: normal;
            cursor: pointer;
            width: 80px;
            height: 26px;
        }
    </style>
    <script type="text/javascript">
        $(function() {
            $("input[value=设置]").click(setRoler);
        })

        function setRoler() {
            var ids = "";
            //选中的节点数据 数组
            var checkNodes = $('#perTree').tree('getChecked');
            $.each(checkNodes, function(i, nodeData) {
                ids += nodeData.id + ",";
            })
            //半选中的节点数据 数组
            var halfNodes = $('#perTree').tree('getChecked', 'indeterminate');
            $.each(halfNodes, function(i, nodeData) {
                ids += nodeData.id + ",";
            });
            //post发送数据到后台
            $.post("/admin/role/SetRolePer", { rid: "@Model.RoleID", newPerIds: ids }, function(jsonObj) {
                $.msgProcess(jsonObj, function() {
                    $.globalHelper.closeCommonWindow();
                });
            }, "json");
        }
    </script>
}
@helper loadSonNode(int parentId)
{
    foreach (var per in Model.AllPers.FindAll(o => o.perParent == parentId))
    {
          @*
         注意：如果当前权限 是 当前角色的权限，而且 整个权限集合中都没有它的子权限，则说明它是一个独立的权限，如果 角色权限 有它，则设置为选中状态
               如果当前权限 是 当前角色的权限，而且 整个权限集合中有它的子权限，则设置为 非选中状态
          *@
    <li data-options="id:@per.perId,@if (Model.RolePers.SingleOrDefault(o => o.perId == per.perId) != null &&
                                         Model.AllPers.FirstOrDefault(o => o.perParent == per.perId) == null)
                                    {
                                        <text>checked:true</text>
                                    }">
        <span>>@per.perName</span>
        <ul>@loadSonNode(per.perId)</ul>
    </li>
    }
}

<input type="button" value="设置" class="btn1"/>
<ul id="perTree" class="easyui-tree" data-options="checkbox:true">
    @loadSonNode(FMS.UI.Helper.EnumHelper.SystemType.AdminMenuId);
    @loadSonNode(FMS.UI.Helper.EnumHelper.SystemType.ComPer);
    @loadSonNode(FMS.UI.Helper.EnumHelper.SystemType.FacPer);
    @loadSonNode(FMS.UI.Helper.EnumHelper.SystemType.FactoryMenuId);
    @loadSonNode(FMS.UI.Helper.EnumHelper.SystemType.ComputerMenuId);
</ul>
<input type="button" value="设置" class="btn1"/>